using Medical.Domain.DepartmentInfo;
using static Medical.Domain.Enum.DepartmentEnum;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace Medical.Api.Write.Dto.DepartmentManagement
{
    /// <summary>
    /// 使用登记和物品批量请求DTO
    /// </summary>
    public class UseRequestDto
    {
        /// <summary>
        /// 使用登记信息
        /// </summary>
        [Required(ErrorMessage = "使用登记数据不能为空")]
        public UseTableDto UseTable { get; set; }

        /// <summary>
        /// 物品列表
        /// </summary>
        public List<ItemTable> ItemTables { get; set; }
    }

    /// <summary>
    /// 使用登记DTO，用于处理日期格式等问题
    /// </summary>
    public class UseTableDto
    {
        /// <summary>
        /// 主键ID
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 物品的Id
        /// </summary>
        public int ItemId { get; set; }

        /// <summary>
        /// 使用单号
        /// </summary>
        public string UseCode { get; set; }

        /// <summary>
        /// 登记科室
        /// </summary>
        public ApplyingUnitEnum Registrationdepartment { get; set; }

        /// <summary>
        /// 登记时间
        /// </summary>
        public DateTime RegistrationTime { get; set; }

        /// <summary>
        /// 登记人
        /// </summary>
        public string RegistrationPerson { get; set; }

        /// <summary>
        /// 登记状态
        /// 1:新增  2：审核
        /// </summary>
        public int RegistrationStatue { get; set; }

        /// <summary>
        /// 患者姓名
        /// </summary>
        public string PatientName { get; set; }

        /// <summary>
        /// 患者性别
        /// </summary>
        public int RecyclingId { get; set; }

        /// <summary>
        /// 患者年龄
        /// </summary>
        public string PatientAge { get; set; }

        /// <summary>
        /// 身份证号
        /// </summary>
        public string Identitycard { get; set; }

        /// <summary>
        /// 就诊科室
        /// </summary>
        public string Visitingdepartment { get; set; }

        /// <summary>
        /// 医生姓名
        /// </summary>
        public string DoctorName { get; set; }

        /// <summary>
        /// 将DTO转换为领域实体
        /// </summary>
        public UseTable ToEntity()
        {
            return new UseTable
            {
                Id = this.Id,
                ItemId = this.ItemId,
                UseCode = this.UseCode,
                Registrationdepartment = this.Registrationdepartment,
                RegistrationTime = this.RegistrationTime,
                RegistrationPerson = this.RegistrationPerson,
                RegistrationStatue = this.RegistrationStatue,
                PatientName = this.PatientName,
                RecyclingId = this.RecyclingId,
                PatientAge = this.PatientAge,
                Identitycard = this.Identitycard,
                Visitingdepartment = this.Visitingdepartment,
                DoctorName = this.DoctorName,
                CreateTime = DateTime.Now, // 设置创建时间为当前时间
                UpdateTime = DateTime.Now  // 设置更新时间为当前时间
            };
        }
    }
}